package com.authManager.server.dao;

import java.util.List;

import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import com.authManager.entity.SysMenu;
import com.baomidou.mybatisplus.mapper.BaseMapper;

/**
 * <p>
 * 【菜单信息】 Mapper 接口
 * </p>
 *
 * @author 小旋风
 * @since 2018-8-17
 */
public interface SysMenuMapper extends BaseMapper<SysMenu> {
	/*
	 * 【1】获取单个对象的方法用 get 做前缀。 【2】获取多个对象的方法用 list 做前缀。 【3】获取统计值的方法用 count 做前缀。
	 * 【4】插入的方法用 save（ 推荐 ） 或 insert 做前缀。 【5】删除的方法用 remove（ 推荐 ） 或 delete 做前缀。
	 * 【6】修改的方法用 update 做前缀。
	 */

	/*
	 * 通用查询结果列 sys_menu_id AS sysMenuId, name AS name, system_code AS systemCode,
	 * page_url AS pageUrl, page_url_type AS pageUrlType, parent_id AS parentId,
	 * site AS site, sort_num AS sortNum, icon AS icon, menu_type AS menuType,
	 * description AS description, button_mark AS buttonMark, field1 AS field1,
	 * field2 AS field2, field3 AS field3, creater AS creater, create_time AS
	 * createTime, updater AS updater, update_time AS updateTime
	 *
	 * 带表名 sys_menu.sys_menu_id AS sysMenuId, sys_menu.name AS name,
	 * sys_menu.system_code AS systemCode, sys_menu.page_url AS pageUrl,
	 * sys_menu.page_url_type AS pageUrlType, sys_menu.parent_id AS parentId,
	 * sys_menu.site AS site, sys_menu.sort_num AS sortNum, sys_menu.icon AS icon,
	 * sys_menu.menu_type AS menuType, sys_menu.description AS description,
	 * sys_menu.button_mark AS buttonMark, sys_menu.field1 AS field1,
	 * sys_menu.field2 AS field2, sys_menu.field3 AS field3, sys_menu.creater AS
	 * creater, sys_menu.create_time AS createTime, sys_menu.updater AS updater,
	 * sys_menu.update_time AS updateTime
	 */
	@Select("SELECT queryChildrenMenuId(${sysMenuId})")
	 public String getMenuChildrenId(@Param("sysMenuId")Long sysMenuId);
	
	 @Select("<script>select "
	 		
			 + "sys_menu.sys_menu_id AS sysMenuId, sys_menu.name AS name, sys_menu.system_code AS systemCode, sys_menu.page_url AS pageUrl, sys_menu.page_url_type AS pageUrlType, sys_menu.parent_id AS parentId, sys_menu.site AS site, sys_menu.sort_num AS sortNum, sys_menu.icon AS icon, sys_menu.menu_type AS menuType, sys_menu.description AS description, sys_menu.button_mark AS buttonMark, sys_menu.field1 AS field1, sys_menu.field2 AS field2, sys_menu.field3 AS field3, sys_menu.creater AS creater, sys_menu.create_time AS createTime, sys_menu.updater AS updater, sys_menu.update_time AS updateTime"
	 		
	 		+ " from sys_menu where <if test='menuSite != null'> sys_menu.site=#{menuSite} and </if> sys_menu.menu_type=1 and sys_menu.sys_menu_id in( select sys_menu_id from sys_role_menu where sys_role_menu.system_code=#{systemCode} and sys_role_id in( select sys_role_id from sys_user_role where sys_user_id=#{sysUserId} ) ) ORDER BY sys_menu.sort_num desc,sys_menu.sys_menu_id asc </script>")
	 public List<SysMenu> listSysMenuByRoleAndUserId(@Param("systemCode")String systemCode,@Param("sysUserId")String sysUserId,@Param("menuSite")String menuSite);
}